#include <stdio.h>
int fdmax(int nbs[20][3], int nb[3], short int n);

int main()
{

    short int n;
    int sum, nbs[20][3];
    scanf("%hd", &n);
    _Bool dep[20] = {0};
    for (short int i = 0; i < n; i++)
    {
        scanf("%d %d %d", &nbs[i][0], &nbs[i][1], &nbs[i][2]);
    }
    for (int i = 0; i < n; i++)
    {
        printf("\n%d", fdmax(nbs, nbs[i], n));
    }
}
/* 迭代求最大值 */
int fdmax(int nbs[20][3], int nb[3], short int n)
{
    int sum = 0, max = 0, tmp[20] = {0};
    for (int i = 0; i < n; i++)
    {
        if (nbs[i][0] >= nb[0] && nbs[i][1] >= nb[1] && nbs[i][0] + nbs[i][1] != nb[0] + nb[1])
        {
            sum = fdmax(nbs, nbs[i], n) + nb[2];
            if (sum > max)
            {
                max = sum;
            }
        }
    }
    if (!max)
    {
        max = nb[2];
    }

    return max;
}
